package com.wei.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wei.entity.Teacher;
import com.wei.entity.vo.TeacherQuery;
import com.wei.service.TeacherService;
import com.wei.mapper.TeacherMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author HASEE
 * @description 针对表【edu_teacher(讲师)】的数据库操作Service实现
 * @createDate 2022-11-23 09:57:54
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher>
        implements TeacherService {

    @Override
    public Page<Teacher> teacherCondition(Integer current, Integer limit, TeacherQuery teacherQuery) {
        Page<Teacher> page = new Page<>(current, limit);
        LambdaQueryWrapper<Teacher> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(teacherQuery.getName()), Teacher::getName, teacherQuery.getName())
                .eq(teacherQuery.getLevel() != null, Teacher::getLevel, teacherQuery.getLevel())
                .ge(StrUtil.isNotBlank(teacherQuery.getBegin()), Teacher::getGmtCreate, teacherQuery.getBegin())
                .le(StrUtil.isNotBlank(teacherQuery.getEnd()), Teacher::getGmtCreate, teacherQuery.getEnd())
                .orderByDesc(Teacher::getGmtCreate);
        page(page, wrapper);
        return page;
    }

    @Override
    public Map<String, Object> showTeacherInfo(Long current, Long limit) {

        Page<Teacher> page = new Page<>(current, limit);

        baseMapper.selectPage(page, null);

        Map<String, Object> map = new HashMap<>();

        map.put("records", page.getRecords());
        map.put("current", page.getCurrent());
        map.put("size", page.getSize());
        map.put("total", page.getTotal());
        map.put("pages", page.getPages());
        map.put("hasNext", page.hasNext());
        map.put("hasPrevious", page.hasPrevious());

        return map;
    }
}




